from flask_wtf import Form
from wtforms import StringField, SubmitField, SelectField, TextAreaField
from wtforms.validators import DataRequired, Regexp
from flask_ckeditor import CKEditor, CKEditorField
from ..models import *
from flask_soeditor import SOEditor

# 上传文件
from flask_uploads import IMAGES, TEXT, AUDIO
from flask_wtf.file import FileRequired, FileField, FileAllowed


# 文件添加测试
class cFormFileUp(Form):
    photo = FileField(validators=[
        FileAllowed(IMAGES + TEXT + AUDIO, u'必须是文件！'),
        FileRequired(u'文件未选择！')])
    submit = SubmitField(u'上传')


class cFormAdminSearch(Form):
    search = StringField('search', validators=[DataRequired()])
    submit = SubmitField('Submit')


##添加列表---表单##################################################################################################
class cFormSchoolAdd(Form):
    # seach = StringField('搜索')
    # seachbutton = SubmitField('搜索')

    schoolname = StringField('名称', validators=[DataRequired()])
    schooladdr = StringField('地址', validators=[DataRequired()])
    schoolpohne = StringField('电话',
                              validators=[DataRequired()])
    schoolfox = StringField('传真',
                            validators=[DataRequired()])

    homepage = StringField('主页',
                           validators=[DataRequired()])
    logo = FileField(validators=[
        FileAllowed(IMAGES + TEXT + AUDIO, u'必须是文件！'),
        FileRequired(u'文件未选择！')])

    disc = CKEditorField('描述', validators=[DataRequired()])
    submitSchoolAdd = SubmitField('添加')


class cFormCollegeAdd(Form):
    name = StringField('名称', validators=[DataRequired()])
    schooleid = SelectField('学校', validators=[DataRequired()], coerce=str)

    def __init__(self, *args, **kwargs):
        super(cFormCollegeAdd, self).__init__(*args, **kwargs)
        ret = tSchool.query.all()

        self.schooleid.choices = [(x.id, x.name) for x in ret]

    submitCollegeAdd = SubmitField('添加')


class cFormMajorAdd(Form):

    name = StringField('名称', validators=[DataRequired()])
    collegeid = SelectField('学院', validators=[DataRequired()], coerce=str)

    def __init__(self, *args, **kwargs):
        super(cFormMajorAdd, self).__init__(*args, **kwargs)
        ret = tCollege.query.all()

        self.collegeid.choices = [(x.id, x.name) for x in ret]

    submitCollegeAdd = SubmitField('添加')


class cFormClazzAdd(Form):
    name = StringField('名称', validators=[DataRequired()])
    major = SelectField('专业', validators=[DataRequired()])

    def __init__(self, *args, **kwargs):
        super(cFormClazzAdd, self).__init__(*args, **kwargs)
        ret = tMajor.query.all()

        self.major.choices = [(x.id, x.name) for x in ret]

    submitClazzAdd = SubmitField('添加')


class cFormPathAdd(Form):
    name = StringField('路径名称', validators=[DataRequired()])

    submitPath = SubmitField('添加')


class cFormPathStepAdd(Form):
    name = StringField('阶段名称', validators=[DataRequired()])
    level = StringField('阶段顺序', validators=[DataRequired()])
    pathname = SelectField('阶段名称', validators=[DataRequired()])

    def __init__(self, *args, **kwargs):
        super(cFormPathStepAdd, self).__init__(*args, **kwargs)
        ret = tPath.query.all()

        self.pathname.choices = [(x.id, x.name) for x in ret]

    submitStepAdd = SubmitField('添加')


class cFormCourseAdd(Form):
    name = StringField('课程名称')
    disc = StringField('描述')

    submitCourseAdd = SubmitField('添加')


class cFormUserAdd(Form):
    name = StringField('名称', validators=[DataRequired()])
    rolename = SelectField('角色', validators=[DataRequired()])

    def __init__(self, *args, **kwargs):
        super(cFormUserAdd, self).__init__(*args, **kwargs)
        ret = tRole.query.all()

        self.rolename.choices = [(x.id, x.name) for x in ret]

    submituserAdd = SubmitField('添加')


class cFormRoleAdd(Form):
    name = StringField('角色', validators=[DataRequired()])

    submitroleAdd = SubmitField('添加')


class cFormModelTypeAdd(Form):
    name = StringField('名称', validators=[DataRequired()])

    submitroleAdd = SubmitField('添加')





class cFormCaptionAdd(Form):
    chptionname=StringField('章节名称',  validators=[DataRequired()])
    coursename = SelectField('课程名称',  validators=[DataRequired()])
    chptionIndex = StringField('章节序号',validators=[DataRequired()])
    chationdisc=StringField('描述', validators=[DataRequired()])
    chptionModel=StringField('模板', validators=[DataRequired()])
    chptiontype=SelectField('类型', validators=[DataRequired()])


    def __init__(self,  *args, **kwargs):
        super(cFormCaptionAdd, self).__init__(*args, **kwargs)
        ret = tModelType.query.all()
        self.chptiontype.choices=[(x.id,x.name) for x in ret]

        ret = tCourse.query.all()
        self.coursename.choices = [(x.id,x.name) for x in ret]

    submitCaptionAdd = SubmitField('添加')


class cFormModelAdd(Form):
    name = StringField('名称', validators=[DataRequired()])
    disc = StringField('描述', validators=[DataRequired()])
    type = SelectField('类型', validators=[DataRequired()])

    modelfile = StringField('模板文件', validators=[DataRequired()])

    def __init__(self,  *args, **kwargs):
        super(cFormModelAdd, self).__init__(*args, **kwargs)
        ret = tModelType.query.all()

        self.type.choices = [(x.id, x.name) for x in ret]

    submitModelAdd = SubmitField('添加')


class cFormPlayerAdd(Form):
    id = StringField('选手编号', validators=[DataRequired])
    name = StringField('选手姓名', validators=[DataRequired])
    disc = StringField('选手描述', validators=[DataRequired])

    submitCaptionAdd = SubmitField('添加')


class cFormMatchAdd(Form):
    id=StringField('比赛编号', validators=[DataRequired])
    name=StringField('比赛名字', validators=[DataRequired])
    modelsid=StringField('模板id', validators=[DataRequired])
    starttime=StringField('开始时间', validators=[DataRequired])
    endtime=StringField('结束时间', validators=[DataRequired])
    studcount=StringField('参赛人数', validators=[DataRequired])
    judgescount=StringField('比赛总分', validators=[DataRequired])

    submitCaptionAdd = SubmitField('添加')


class cFormJugerAdd(Form):
    userid = StringField('裁判编号', validators=[DataRequired()])
    matchid = StringField('比赛编号', validators=[DataRequired()])

    submitJudgerAdd = SubmitField('添加')

####展示列表--表单#############################################################################################

#展示列表头-通用表单
class cFormShowListHead(Form):

    submitAccept = SubmitField('同意')
    submitRefuse = SubmitField('拒绝')
    submitAdd = SubmitField('添加')
    submitDel = SubmitField('删除')

#模板列表单行---提交表单
